package day_2022_12_to_3.year2023;

/**
 * @author haomin
 * @date 2023/01/16 20:49
 **/
public class Day1_16_Num1813 {
    class Solution {
        public boolean areSentencesSimilar(String sentence1, String sentence2) {
            String[] str1 = sentence1.split(" ");
            String[] str2 = sentence2.split(" ");
            if(str1.length < str2.length) {
                String[] temp = str1;
                str1 = str2;
                str2 = temp;
            }
            int l2 = 0, r2 = str2.length-1;
            int l1 = 0, r1 = str1.length-1;
            while(l2 <= r2 && str1[l1].equals(str2[l2])) {
                l1++; l2++;
            }
            while(l2 <= r2 && str1[r1].equals(str2[r2])) {
                r1--;
                r2--;
            }
            return r2 - l2 == -1;
        }
    }
}